<?php
/**
 * Created by PhpStorm.
 * User: haodian
 * Date: 2018/7/25
 * Time: 15:00
 */

namespace App\Http\Controllers\Index;


use App\Base\BaseFunc;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class HuController extends Controller
{
    public function addGameJPG(Request $request,BaseFunc $baseFunc)
    {
        $file = $request->file('files');
        $file_name = date('YmdHis').rand(1000,9999).".".$file->getClientOriginalExtension();
        $destinationPath = public_path() . '/';
        $file->move($destinationPath, $file_name);
        $game_jpg_name = $request->input('game_jpg_name');
        $game_jpg_time = date('Y-m-d H:i:s');
        $game_jpg_status = 0;
        //dd($goods_class);
        $image = '/' . $file_name;
        //dd($goods_name);
        try {
            DB::table('game_jpg')->insertGetId([
                "game_jpg_address" => $image,
                "game_jpg_name" => $game_jpg_name,
                "game_jpg_time" => $game_jpg_time,
                "game_jpg_status" => $game_jpg_status
            ]);
            $baseFunc->setRedirectMessage(true,'上传成功，等待审核',NULL,'/newIndex.blade.php');
            //return redirect('/myGoods');
        } catch (\Exception $e) {
            return response()->json([
                'message' => $e->getMessage()
            ]);
        }
    }

    public function gameJPGList()
    {
        $data['gameJPGList'] = DB::table('game_jpg')
            ->where('game_jpg_status',1)
            ->where('game_jpg_floor',session('ad_floor'))
            ->orderby('game_jpg_id','desc')
            ->paginate(10);
        return view('/index.hu.gameJPGList',$data);
    }

    public function gameJPGInfo($game_jpg_id)
    {
        $data['gameJPGInfo'] = DB::table('game_jpg')
            ->where('game_jpg_id',$game_jpg_id)
            ->first();
        return view('/index.hu.gameJPGInfo',$data);
    }

    public function addUserJPG(Request $request,BaseFunc $baseFunc)
    {
        $file = $request->file('files');
        $file_name = $file->getClientOriginalName();
        $destinationPath = public_path() . '/';
        $file->move($destinationPath, $file_name);
        $user_jpg_name = $request->input('user_jpg_name');
        $user_jpg_time = date('Y-m-d H:i:s');
        $user_jpg_status = 0;
        $user_jpg_floor = session('ad_floor');
        //dd($goods_class);
        $image = '/' . $file_name;
        //dd($goods_name);
        try {
            DB::table('user_jpg')->insertGetId([
                "user_jpg_address" => $image,
                "user_jpg_name" => $user_jpg_name,
                "user_jpg_time" => $user_jpg_time,
                "user_jpg_status" => $user_jpg_status,
                "user_jpg_floor" => $user_jpg_floor
            ]);
            $baseFunc->setRedirectMessage(true,'上传成功，等待审核',NULL,NULL);
            return redirect()->back();
        } catch (\Exception $e) {
            return response()->json([
                'message' => $e->getMessage()
            ]);
        }
    }

    public function userJPGList()
    {
        $data['userJPGList'] = DB::table('user_jpg')
            ->where('user_jpg_status',1)
            ->where('user_jpg_floor',session('ad_floor'))
            ->orderby('user_jpg_id','desc')
            ->paginate(10);
        return view('/index.hu.userJPGList',$data);
    }

    public function userJPGInfo($user_jpg_id)
    {
        $data['userJPGInfo'] = DB::table('user_jpg')
            ->where('user_jpg_id',$user_jpg_id)
            ->first();
        return view('/index.hu.userJPGInfo',$data);
    }

    public function addEXP(BaseFunc $baseFunc)
    {
        $input = Input::only('user_exp_name','user_exp_info');
        $input['user_exp_time'] = date('Y-m-d H:i:s');
        $input['user_exp_status'] = 0;
        DB::table('user_exp')->insert($input);
        $baseFunc->setRedirectMessage(true,'上传成功，等待审核',NULL,NULL);
        return redirect()->back();
    }

    public function userExpList()
    {
        $data['userExpList'] = DB::table('user_exp')
            ->where('user_exp_status',1)
            ->where('user_exp_floor',session('ad_floor'))
            ->orderby('user_exp_id','desc')
            ->paginate(10);
        return view('/index.hu.userExpList',$data);
    }

    public function userExpInfo($id)
    {
        $data['userExp'] = DB::table('user_exp')
            ->where('user_exp_id',$id)
            ->first();
        return view('/index.hu.userExpInfo',$data);
    }

    public function addArticle(BaseFunc $baseFunc)
    {
        $input = Input::only('user_article_name','user_article_info');
        $input['user_article_time'] = date('Y-m-d H:i:s');
        $input['user_article_status'] = 0;
        DB::table('user_article')->insert($input);
        $baseFunc->setRedirectMessage(true,'上传成功，等待审核',NULL,NULL);
        return redirect()->back();
    }

    public function userArticleList()
    {
        $data['userArticleList'] = DB::table('user_article')
            ->where('user_article_status',1)
            ->where('user_article_floor',session('ad_floor'))
            ->orderby('user_article_id','desc')
            ->paginate(10);
        return view('/index.hu.userArticleList',$data);
    }

    public function userArticleInfo($id)
    {
        $data['userArticle'] = DB::table('user_article')
            ->where('user_article_id',$id)
            ->first();
        return view('/index.hu.userArticleInfo',$data);
    }

    public function mpActionList()
    {
        $data['mpActionList'] = DB::table('mp_action')
            ->where('mp_action_floor',session('ad_floor'))
            ->orderby('mp_action_id','desc')
            ->paginate(10);
        return view('/index.hu.mpActionList',$data);
    }

    public function mpActionInfo($id)
    {
        $data['mpAction'] = DB::table('mp_action')
            ->where('mp_action_id',$id)
            ->first();
        return view('/index.hu.mpActionInfo',$data);
    }

}